import 'package:ichinesereader/models/book/BookProgress.dart';
import 'package:ichinesereader/models/student/AssignmentDetail.dart';
import 'dart:convert';

List<Assignment> assignmentsFromJson(String str) =>
    List<Assignment>.from(json.decode(str).map((x) => Assignment.fromJson(x)));

String assignmentsToJson(List<Assignment> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

Assignment assignmentFromJson(String str) => Assignment.fromJson(json.decode(str));

class Assignment {
  Assignment({
    this.assignment,
    this.bookProgress,
    this.overallCount,
    this.overallProgress,
    this.quizAttempted,
    this.quizPassed,
    this.readComplete,
    this.readProgress,
    this.readStarted,
    this.recording,
    this.writing,
  });

  AssignmentDetail? assignment;
  List<BookProgress>? bookProgress;
  int? overallCount;
  int? overallProgress;
  bool? quizAttempted;
  bool? quizPassed;
  bool? readComplete;
  int? readProgress;
  bool? readStarted;
  bool? recording;
  bool? writing;

  factory Assignment.fromJson(Map<String, dynamic> json) => Assignment(
        assignment: json["assignment"] != null
            ? AssignmentDetail.fromJson(json["assignment"])
            : null,
        bookProgress: json["bookProgress"] != null
            ? List<BookProgress>.from(
                json["bookProgress"].map((x) => BookProgress.fromJson(x)))
            : null,
        overallCount: json["overallCount"],
        overallProgress: json["overallProgress"],
        quizAttempted: json["quizAttempted"],
        quizPassed: json["quizPassed"],
        readComplete: json["readComplete"],
        readProgress: json["readProgress"],
        readStarted: json["readStarted"],
        recording: json["recording"],
        writing: json["writing"],
      );

  Map<String, dynamic> toJson() => {
        "assignment": assignment != null ? assignment?.toJson() : null,
        "bookProgress": bookProgress != null
            ? List<dynamic>.from(bookProgress!.map((x) => x.toJson()))
            : null,
        "overallCount": overallCount,
        "overallProgress": overallProgress,
        "quizAttempted": quizAttempted,
        "quizPassed": quizPassed,
        "readComplete": readComplete,
        "readProgress": readProgress,
        "readStarted": readStarted,
        "recording": recording,
        "writing": writing,
      };
}
